package com.kkd.kkdapp.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.kkd.kkdapp.R;
import com.kkd.kkdapp.http.entity.ExperienceGoldDetailDataItem;

public class ExperienceGoldDetailAdapter2 extends BaseAdapter {
	private Context mContext;
	private LayoutInflater inflater;
	private List<ExperienceGoldDetailDataItem> list;

	public ExperienceGoldDetailAdapter2(Context context,
			List<ExperienceGoldDetailDataItem> list) {
		mContext = context;
		inflater = LayoutInflater.from(mContext);
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHodler hodler = null;
		if (convertView == null) {
			convertView = View.inflate(mContext,
					R.layout.everyday_listview_item, null);
			hodler = new ViewHodler();
			convertView.setTag(hodler);
			hodler.deal_title = (TextView) convertView
					.findViewById(R.id.deal_title);
			hodler.deal_timer = (TextView) convertView
					.findViewById(R.id.deal_timer);
			hodler.deal_money = (TextView) convertView
					.findViewById(R.id.deal_money);
			hodler.line = convertView.findViewById(R.id.line);
		} else {
			hodler = (ViewHodler) convertView.getTag();
		}
		if (position == 0) {
			hodler.line.setVisibility(View.GONE);
		} else {
			hodler.line.setVisibility(View.VISIBLE);
		}
		hodler.deal_title.setText(list.get(position).getTradeDesc());
		if (list.get(position).getCreateTime().contains("/")) {
			hodler.deal_timer.setText(list.get(position).getCreateTime()
					.replace("/", "-"));
		} else {
			hodler.deal_timer.setText(list.get(position).getCreateTime());
		}

		if (list.get(position).getAmount().contains("+")) {
			hodler.deal_money.setTextColor(Color.parseColor("#FF7301"));
		} else {
			hodler.deal_money.setTextColor(Color.parseColor("#38BCA4"));
		}
		hodler.deal_money.setText(list.get(position).getAmount());

		return convertView;
	}

	class ViewHodler {
		TextView deal_title;
		TextView deal_timer;
		TextView deal_money;
		View line;
	}
}
